﻿using System.Data.Entity;
using LifeMed.Data.Core.ContextFactory;

namespace LifeMed.Data.Core.UOW
{
    public class UnitOfWork : IUnitOfWork
    {
        private readonly IDbContextFactory _dbContextFactory;
        private DbContext _dbContext;

        public UnitOfWork(IDbContextFactory dbContextFactory)
        {
            _dbContextFactory = dbContextFactory;
        }

        protected DbContext DataContext
        {
            get { return _dbContext ?? (_dbContext = _dbContextFactory.Instance); }
        }

        public void Commit()
        {
            DataContext.SaveChanges();
        }
    }
}